package com.itcam.list_.collection_.set_.hashset;


import com.itcam.list_.collection_.set_.domain.Student;

import java.util.HashSet;

/**
 * Author:Cammy.Wu
 * Date:2024-06-05
 * Description:
 */

public class HashSetDemo02 {
    /**
     * HashSet集合存储自定义对象
     *
     * @param args
     */
    public static void main(String[] args) {
        HashSet<Student> hashSet = new HashSet<>();

        hashSet.add(new Student("cammy", 24));
        hashSet.add(new Student("jerry", 20));
        hashSet.add(new Student("lixing", 23));
        hashSet.add(new Student("lixing", 23));
        // 对象必须重写equals和hashCode方法才能够去重

        System.out.println("hashSet = " + hashSet);
    }
}
